/*
 *  POJ1018: Communication System
 */

/*-------- Includes --------*/
#include <iostream>
#include <iomanip>
#include <algorithm>

using namespace std;

/*-------- Defines --------*/
#define INF 1000000000

/*-------- Types --------*/


/*-------- Global Variables --------*/
int t, n;
int m;
int B, P;
int dp[100][401];

/*-------- Function Prototypes --------*/


/*-------- Main Function --------*/
int main(int argc, char const *argv[])
{
    // get input
    cin >> t;

    while (t--) {
        cin >> n;

        for (int i = 0; i < n; i++)
            for (int j = 0; j < 401; j++)
                dp[i][j] = INF;

        /* dynamic programming */
        // When i = 0
        // get input
        cin >> m;

        for (int i = 0; i < m; i++) {
            cin >> B >> P;

            dp[0][B] = min(dp[0][B], P);
        }

        // When i = [1...n-1]
        for (int i = 1; i < n; i++) {
            // get input
            cin >> m;

            for (int j = 0; j < m; j++) {
                cin >> B >> P;

                for (int k = 1; k < 401; k++) {
                    if (dp[i - 1][k] < INF) {
                        int b = min(k, B);

                        dp[i][b] = min(dp[i][b], dp[i - 1][k] + P);
                    }
                }
            }
        }

        // find the maximum
        double maxi = 0.0;
        for (int i = 1; i < 401; i++) {
            if (dp[n -1][i] < INF) {
                double temp = (double) i / dp[n - 1][i];

                if (temp > maxi) maxi = temp;
            }
        }

        cout << fixed << setprecision(3) << maxi << endl;
    }

    return 0;
}

/*-------- Functions --------*/

